package acwing._1_1AlgorithmBasic._3SearchGraph;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._3SearchGraph
 * @File : Q0852.java
 * @Author : WangRuoyu
 * @Date : 2023/4/3 9:49
 */

import java.io.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class Q0852 {
    static int n;
    static int m;
    static int[] w;
    static int[] h;
    static int[] e;
    static int[] next;
    static int idx = 0;

    static void add(int a, int b, int c) {
        w[idx] = c;
        e[idx] = b;
        next[idx] = h[a];
        h[a] = idx++;
    }

    static boolean spfa() {
        int[] res = new int[n + 1];
        boolean[] st = new boolean[n + 1];
        int[] cnt = new int[n + 1];

        Queue<Integer> q = new LinkedList<>();
        for (int i = 1; i <= n; ++i) {
            q.add(i);
            st[i] = true;
        }

        while (!q.isEmpty()) {
            int point = q.poll();
            st[point] = false;

            for (int i = h[point]; i != -1; i = next[i]) {
                int j = e[i];
                if (res[j] > res[point] + w[i]) {
                    res[j] = res[point] + w[i];
                    cnt[j] = cnt[point] + 1;
                    if (cnt[j] >= n) {
                        return true;
                    }
                    if (!st[j]) {
                        q.add(j);
                        st[j] = true;
                    }
                }
            }
        }

        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        m = Integer.parseInt(words[1]);
        w = new int[m + 10];
        e = new int[m + 10];
        next = new int[m + 10];
        h = new int[n + 1];
        Arrays.fill(h, -1);

        for (int i = 0; i < m; i++) {
            words = br.readLine().split(" ");
            add(Integer.parseInt(words[0]), Integer.parseInt(words[1]), Integer.parseInt(words[2]));
        }

        if (spfa()) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}
